package com.lehecai.core.api.credit;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * Created by zhangzq on 14-2-21.
 */
public class CreditExchangeGoods extends AbstractApiResultBean {

    public static final String QUERY_ID = "id";
    public static final String QUERY_NAME = "name";
    public static final String QUERY_CLASSES = "type";//一级
    public static final String QUERY_TYPE = "sort";//二级
    public static final String QUERY_RECOMMEND = "is_recommended";
    public static final String QUERY_PALTFORM = "platform";

    public static final String SET_ID = "id";
    public static final String SET_NAME = "name";
    public static final String SET_GOODS_PIC = "goods_pic";
    public static final String SET_DESCRIPTION = "description";
    public static final String SET_CONVERSION_PRICE = "conversion_price";
    public static final String SET_REFERENCE_PRICE = "reference_price";
    public static final String SET_CLASSES = "type";
    public static final String SET_TYPE = "sort";
    public static final String SET_DELIVERY = "delivery";
    public static final String SET_TOTAL_NUM = "total_num";
    public static final String SET_STARTSALE_AT = "startsale_at";
    public static final String SET_ENDSALE_TIME = "endsale_at";
    public static final String SET_SINGLE_LIMITED = "single_limited";
    public static final String SET_ISRECOMMEND = "is_recommended";
    public static final String SET_PROP_ID = "prop_id";
    public static final String SET_PALTFORM = "platform";

    public static  final String ORDER_CREATEAT = "create_at";

    private Integer id;			//编号，必选
    private String name;       //品名，必选
    private String goodsPic;	//图片，必选
    private String description;	//描述，必选
    private Integer conversionPrice;	//兑换价, 必选
    private String referencePrice;	//参考价，可选
    private GoodsClassesType goodsClassesType;//一级商品类型 必选
    private GoodsType goodsType;//二级商品类型  必选
    private DeliveryType delivery;	//支付方式，可选  是否物流
    private Integer totalNum;	//数量, 必选      total_num
    private Date startSaleAt;	//上架时间，可选   startsale_at
    private Date endSaleAt;	//有效期限，可选   endsale_at
    private Integer singleLimited;	//单次可兑换上限，可选 single_limited
    private YesNoStatus isRecommended;	//是否推荐，可选  is_recommended
    private String propId;//道具编号
    private SupportPlatformType supportPlatformType;

    private Integer exchangedNum;//兑换量
    private YesNoStatus isHot;//是否热门 is_hot
    private YesNoStatus isNew;//是否新品is_new
    private YesNoStatus isTimeLimited;//是否限时is_time_limited
    private Integer exchangeHeat;//兑换热度 exchange_heat
    private Date createAt;//创建时间
    private Date updateAt;//更新时间
    private Integer status;//

    public static CreditExchangeGoods convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        CreditExchangeGoods creditExchangeGoods = new CreditExchangeGoods();
        creditExchangeGoods.id = getInt(object, "id");
        creditExchangeGoods.name = getString(object, "name");
        creditExchangeGoods.goodsPic = getString(object, "goods_pic");
        creditExchangeGoods.description = getString(object, "description");
        creditExchangeGoods.conversionPrice = getInt(object, "conversion_price") ;
        creditExchangeGoods.referencePrice = getString(object, "reference_price");
        creditExchangeGoods.goodsClassesType = GoodsClassesType.getItem(object.getInt("type"));
        creditExchangeGoods.goodsType = GoodsType.getItem(object.getInt("sort"));
        creditExchangeGoods.delivery = DeliveryType.getItem(object.getInt("delivery"));
        creditExchangeGoods.totalNum = getInt(object, "total_num");
        creditExchangeGoods.startSaleAt = CoreDateUtils.parseDate(("".equals(getString(object, "startsale_at")) || "0000-00-00 00:00:00".equals(getString(object, "startsale_at"))) ? null : getString(object, "startsale_at"), CoreDateUtils.DATETIME);
        creditExchangeGoods.endSaleAt = CoreDateUtils.parseDate(("".equals(getString(object, "endsale_at")) || "0000-00-00 00:00:00".equals(getString(object, "endsale_at"))) ? null : getString(object, "endsale_at"), CoreDateUtils.DATETIME);
        creditExchangeGoods.singleLimited = getInt(object, "single_limited");
        creditExchangeGoods.isRecommended = YesNoStatus.getItem(object.getInt("is_recommended"));
        creditExchangeGoods.exchangedNum = object.getInt("exchanged_num");
        creditExchangeGoods.isHot = YesNoStatus.getItem(object.getInt("is_hot"));
        creditExchangeGoods.isNew = YesNoStatus.getItem(object.getInt("is_new"));
        creditExchangeGoods.isTimeLimited = YesNoStatus.getItem(object.getInt("is_time_limited"));
        creditExchangeGoods.exchangeHeat = object.getInt("exchange_heat");
        creditExchangeGoods.createAt = CoreDateUtils.parseDate(("".equals(getString(object, "create_at")) || "0000-00-00 00:00:00".equals(getString(object, "create_at"))) ? null : getString(object, "create_at"), CoreDateUtils.DATETIME);
        creditExchangeGoods.updateAt = CoreDateUtils.parseDate(("".equals(getString(object, "update_at")) || "0000-00-00 00:00:00".equals(getString(object, "update_at"))) ? null : getString(object, "update_at"), CoreDateUtils.DATETIME);
        creditExchangeGoods.propId = getString(object, "prop_id") ;
        creditExchangeGoods.status = getInt(object, "status") ;
        creditExchangeGoods.supportPlatformType = SupportPlatformType.getItem(object.getInt("platform"));
        return creditExchangeGoods;
    }

    public static List<CreditExchangeGoods> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<CreditExchangeGoods> list = new ArrayList<CreditExchangeGoods>();
        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGoodsPic() {
        return goodsPic;
    }

    public void setGoodsPic(String goodsPic) {
        this.goodsPic = goodsPic;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getConversionPrice() {
        return conversionPrice;
    }

    public void setConversionPrice(Integer conversionPrice) {
        this.conversionPrice = conversionPrice;
    }

    public String getReferencePrice() {
        return referencePrice;
    }

    public void setReferencePrice(String referencePrice) {
        this.referencePrice = referencePrice;
    }

    public GoodsClassesType getGoodsClassesType() {
        return goodsClassesType;
    }

    public void setGoodsClassesType(GoodsClassesType goodsClassesType) {
        this.goodsClassesType = goodsClassesType;
    }

    public GoodsType getGoodsType() {
        return goodsType;
    }

    public void setGoodsType(GoodsType goodsType) {
        this.goodsType = goodsType;
    }

    public DeliveryType getDelivery() {
        return delivery;
    }

    public void setDelivery(DeliveryType delivery) {
        this.delivery = delivery;
    }

    public Integer getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(Integer totalNum) {
        this.totalNum = totalNum;
    }

    public Date getStartSaleAt() {
        return startSaleAt;
    }

    public void setStartSaleAt(Date startSaleAt) {
        this.startSaleAt = startSaleAt;
    }

    public Date getEndSaleAt() {
        return endSaleAt;
    }

    public void setEndSaleAt(Date endSaleAt) {
        this.endSaleAt = endSaleAt;
    }

    public Integer getSingleLimited() {
        return singleLimited;
    }

    public void setSingleLimited(Integer singleLimited) {
        this.singleLimited = singleLimited;
    }

    public Integer getExchangedNum() {
        return exchangedNum;
    }
    public void setExchangedNum(Integer exchangedNum) {
        this.exchangedNum = exchangedNum;
    }

    public YesNoStatus getIsHot() {
        return isHot;
    }

    public void setIsHot(YesNoStatus isHot) {
        this.isHot = isHot;
    }

    public YesNoStatus getIsNew() {
        return isNew;
    }

    public void setIsNew(YesNoStatus isNew) {
        this.isNew = isNew;
    }

    public YesNoStatus getIsTimeLimited() {
        return isTimeLimited;
    }

    public void setIsTimeLimited(YesNoStatus isTimeLimited) {
        this.isTimeLimited = isTimeLimited;
    }

    public Integer getExchangeHeat() {
        return exchangeHeat;
    }

    public void setExchangeHeat(Integer exchangeHeat) {
        this.exchangeHeat = exchangeHeat;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public Date getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(Date updateAt) {
        this.updateAt = updateAt;
    }

    public String getPropId() {
        return propId;
    }

    public void setPropId(String propId) {
        this.propId = propId;
    }

    public YesNoStatus getIsRecommended() {
        return isRecommended;
    }

    public void setIsRecommended(YesNoStatus isRecommended) {
        this.isRecommended = isRecommended;
    }

    public SupportPlatformType getSupportPlatformType() {
        return supportPlatformType;
    }

    public void setSupportPlatformType(SupportPlatformType supportPlatformType) {
        this.supportPlatformType = supportPlatformType;
    }
}
